function isSameWeek(date1, date2) {
    const parseDate = (str) => {
        const year = parseInt(str.slice(0, 4));
        const month = parseInt(str.slice(4, 6)) - 1;
        const day = parseInt(str.slice(6));
        return new Date(year, month, day);
    };

    const d1 = parseDate(date1);
    const d2 = parseDate(date2);

    // 使用ISO周数计算
    const getISOWeek = (date) => {
        const d = new Date(date);
        d.setHours(0, 0, 0, 0);
        d.setDate(d.getDate() + 4 - (d.getDay() || 7)); // 调整到最近的周四
        const yearStart = new Date(d.getFullYear(), 0, 1);
        return Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
    };

    const year1 = d1.getFullYear();
    const year2 = d2.getFullYear();
    const week1 = getISOWeek(d1);
    const week2 = getISOWeek(d2);

    // 同一ISO年周数或跨年周（如年末和年初）
    return (year1 === year2 && week1 === week2) || 
           (Math.abs(d1 - d2) < 7 * 86400000 && week1 !== week2);
}

console.log(isSameWeek("20250101", "20250102")); // true